package com.example.admin.yuejian_22.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.admin.yuejian_22.Bean.MyPhotoBean;
import com.example.admin.yuejian_22.Bean.PhotoBean;
import com.example.admin.yuejian_22.Bean.UserBean;
import com.example.admin.yuejian_22.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Admin on 2017/11/10.
 */

public class MyPhotoAdapter extends RecyclerView.Adapter {
    private Context Contexts;
    private List<MyPhotoBean> photoBeanList;
   private UserBean userBeanList;
    private LayoutInflater LayoutInflater;


    public MyPhotoAdapter(Context Contexts, List<MyPhotoBean> photoBeanList,UserBean userBeanList) {
        this.Contexts = Contexts;
        this.photoBeanList = photoBeanList;
        this.userBeanList = userBeanList;
        LayoutInflater = LayoutInflater.from(Contexts);
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_myphoto, parent, false);

        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final MyPhotoBean entity = photoBeanList.get(position);
        if (null == entity) return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.myphoto_time.setText(entity.getUpdate_time());
        viewHolder.myphoto_intro.setText(entity.getTitle());
        if (!entity.getThumb0().isEmpty()) {
            Picasso.with(Contexts).load("http://172.24.10.175/workout/Uploads/" + entity.getThumb0()).into(viewHolder.myphoto_thumb);
        } else {
            viewHolder.myphoto_thumb.setImageResource(R.drawable.ic_club);
        }


        viewHolder.myphoto_username.setText(userBeanList.getUser_name());
//        if (!(userBeanList.getPhoto() !=null)) {
//            Picasso.with(Contexts).load("http://172.24.10.175/workout/Uploads/" + userBeanList.getPhoto()).into(viewHolder.myphoto_view);
//        } else {
//            viewHolder.myphoto_view.setImageResource(R.drawable.ic_club);
//        }
//
 }
        public class ViewHolder extends RecyclerView.ViewHolder {

            ImageView myphoto_view;
            TextView myphoto_username;

            TextView myphoto_time;
            TextView myphoto_intro;
            ImageView myphoto_thumb;

            public ViewHolder(View itemView) {
                super(itemView);
                myphoto_view = (ImageView) itemView.findViewById(R.id.myphoto_view);
                myphoto_username = (TextView) itemView.findViewById(R.id.myphoto_username);

                myphoto_time = (TextView) itemView.findViewById(R.id.myphoto_time);
                myphoto_intro = (TextView) itemView.findViewById(R.id.myphoto_intro);
                myphoto_thumb = (ImageView) itemView.findViewById(R.id.myphoto_thumb);

            }
        }
    @Override
    public int getItemCount() {
            return photoBeanList.size();
    }
}
